/*------------------------------------------------------------------------------*\
**   Copyright 2008 Jonhnny Weslley                                             **
**                                                                              **
**   Licensed under the Apache License, Version 2.0 (the "License");            **
**   you may not use this file except in compliance with the License.           **
**   You may obtain a copy of the License at                                    **
**                                                                              **
**       http://www.apache.org/licenses/LICENSE-2.0                             **
**                                                                              **
**   Unless required by applicable law or agreed to in writing, software        **
**   distributed under the License is distributed on an "AS IS" BASIS,          **
**   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   **
**   See the License for the specific language governing permissions and        **
**   limitations under the License.                                             **
\*------------------------------------------------------------------------------*/

package shibernate.petclinic

import java.util.Date
import scala.reflect.BeanProperty
import javax.persistence.{Id, Entity, Embeddable, Embedded, ManyToOne, MappedSuperclass, Temporal, TemporalType}

object Petclinic extends Application {

}

@MappedSuperclass
class BaseEntity {

  @Id var id: Long = _

}

@MappedSuperclass
class NamedEntity extends BaseEntity {
  @BeanProperty var name: String = _
}

@MappedSuperclass
class Person extends BaseEntity {

  @BeanProperty var firstName: String = _
  @BeanProperty var lastName: String = _

}

@Embeddable
class ContactInfo {
  @BeanProperty var homePhoneNumber: String = _
  @BeanProperty var workPhoneNumber: String = _
  @BeanProperty var faxNumber: String = _
  @BeanProperty var emailAddress: String = _
}

@Embeddable
class Address {
  @BeanProperty var street: String = _ 
  @BeanProperty var zipCode: String = _
  @ManyToOne @BeanProperty var city: City = _
}

@Entity
class Owner extends Person {
  @Embedded @BeanProperty var address: Address = _
  @Embedded @BeanProperty var contact: ContactInfo = _
  @BeanProperty var pets: Set[Pet] = Set.empty
}

@Entity
class Veterinarian extends Person {
  @BeanProperty var specialities: Set[Speciality] = Set.empty
  
  def numberOfSpecialities = specialities.size
}

@Entity
class City extends NamedEntity {
  @BeanProperty var state: String = _
}

@Entity
class PetType extends NamedEntity {
}

@Entity
class Speciality extends NamedEntity {
}

@Entity
class Pet extends NamedEntity {
  @Temporal(TemporalType.DATE) @BeanProperty var birthDate: Date = _
  @BeanProperty var petType: PetType = _
  @BeanProperty var owner: Owner = _
  @BeanProperty var visits: Set[Visit] = Set.empty
}

@Entity
class Visit extends BaseEntity {
  @Temporal(TemporalType.DATE) @BeanProperty var date: Date = new Date
  @BeanProperty var description: String = _
  @BeanProperty var pet: Pet = _
}
